
/**
 * @货币折扣组件
 */
export class Discount {
  constructor(target, options) {
    this.element = target;
    if (typeof target == 'string') {
      this.element = document.querySelector(target);
    }
    if (!this.element) {
      return console.error('实例子不存在');
    }
    this.init(options);
    return this;
  }
  init(options) {
    this.placeholder = options.placeholder ? options.placeholder : '';
    this.lang = options.lang ? options.lang : navigator.language;
    this.title = this.title = options.showHint
      ? options.hintMode == 'placeholder'
        ? this.placeholder
        : options.hintMsg
      : '';
    this.dataChange = options.dataChange ? options.dataChange : () => { };
    this.focus = options.focus ? options.focus : () => { };
    this.type = options.type ? options.type : 'currency';
    this.value = options.value ? options.value : '';
    this.tabindex = options.tabindex;
    //1:四舍五入 2: 舍弃超出精度
    this.fixedRule = options.fixedRule;
    //精度
    this.precision =
      options.precision || options.precision == '0' ? options.precision : 3;
    if (options.type == 'discount') {
      if (this.lang == 'zh-CN') {
        this.precision = 1;
      } else {
        this.precision = 0;
      }
    }
    //步长
    this.steps = options.step ? options.step : 1;
    //千分位
    this.group = new Intl.NumberFormat(this.lang)
      .format(1111)
      .replace(/1/g, '');
    //小数点
    this.decimal = new Intl.NumberFormat(this.lang)
      .format(1.1)
      .replace(/1/g, '');
    //
    this.prefix = options.prefix ? options.prefix : null;
    this.readonly = options.readonly ? options.readonly : false;
    this.element.style.direction = this.direction = options.direction || 'ltr';
    this.validate = options.validate;
    this.max = options.max;
    this.min = options.min;
    this.showSpinButtons = options.showSpinButtons;
    this.render();
    this.value ? this.setValue(this.value) : '';
    return this;
  }
  render() {
    let style = `
		.TeldDiscountComponent{
			//height: 32px;
			//border: 1px solid #DADFEB;
			//box-shadow: 0px 4px 12px 0px rgba(217, 217, 217, 0.25);
			border-radius: 4px;
			align-items: center;
			display: grid;

			font-size:14px;
			overflow:hidden;
      margin-left:2px
		}
		.TeldDiscountComponent .TeldDiscountComponent_prefix,.TeldDiscountComponent .TeldDiscountComponent_suffix{
			flex: 1;
			width: auto;
			// padding: 0 0px 0 10px;
       padding: 0;
			color: #4E5969;
			margin-right:10px;
		}
		.TeldDiscountComponent .TeldDiscountComponent_value{
			width: 100%;
			border: 0;
			outline: 0;
			font-size: 14px;
			text-indent:8px;
			height:100%;
			cursor: pointer;
			ime-mode:disabled;
      background:rgba(0,0,0,0) !important;
      color:rgba(0,0,0, var(--t-color-opacity, /*批量处理90%透明度*/0.9)) !important;
		}
		// .TeldDiscountComponent .TeldDiscountComponent_value::placeholder{
		// 	color: #C9CDD4;
		// 	font-size: 14px;
		// }
		.TeldDiscountComponent .TeldComponent_steps{
			margin-top: 5%;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			height: 100%;
			cursor: pointer;
			transform: scale(1.1);
			// ${this.direction == 'RTL' ? 'margin-left: 14px;' : 'margin-right: 14px;'}
		}
		.TeldDiscountComponent .TeldComponent_steps .triangleTop {
			width: 0;
			height: 0;
			border-style: solid;
			border-width: 0 4px 6px 4px;
			border-color: transparent transparent rgba(0,0,0,.4) transparent;

		}
		.TeldDiscountComponent .TeldComponent_steps .triangleBottom {
			width: 0;
			height: 0;
			border-style: solid;
			border-width: 6px 4px 0px 4px;
			border-color: rgba(0,0,0,.4)  transparent transparent transparent;

		}
		.TeldDiscountComponent:not(.isReadonly) .TeldComponent_steps .triangleBottom:hover{
			border-color: rgba(102, 174, 229, 1)  transparent transparent transparent;
			cursor: pointer;
		}
		.TeldDiscountComponent:not(.isReadonly) .TeldComponent_steps .triangleTop:hover{
		border-color:transparent transparent rgba(102, 174, 229, 1) transparent !important;
			cursor: pointer;
		}
		.TeldDiscountComponent .TeldComponent_steps .triangleBottom.isClick{
			border-color:  #d9d9d9  transparent transparent transparent !important;
		}
		.TeldDiscountComponent:not(.isReadonly) .TeldComponent_steps .triangleTop.isClick{
			border-color:transparent transparent #d9d9d9 transparent !important;

			border-color:var(--color-hover) 		}
		.Teld_Multilingual_Focus,.TeldDiscountComponent:not(.isReadonly):hover{!important;
		}
		.TeldDiscountComponent.isReadonly input{
			background: rgba(0,0,0,0);
		}
		`;
    let ComponentBaseInfo = {};
    if (this.type == 'discount') {
      ComponentBaseInfo = this.formatByLanguage('', this.lang);
    } else {
      ComponentBaseInfo = {
        prefix: this.prefix ? this.prefix : currencySymbols[this.lang],
        value: this.value,
      };
    }
    let html = `
		<style>
		${style}
		</style>
		<div class="TeldDiscountComponent" style="${!ComponentBaseInfo.prefix ? 'grid-template-columns: 1fr auto;' : 'grid-template-columns: auto 1fr auto;'}">
			${
        !ComponentBaseInfo.prefix
          ? ''
          : `
				<span class="TeldDiscountComponent_prefix" >
					${ComponentBaseInfo.prefix}
				</span>
			`
      }
			<input tabindex=${this.tabindex} pattern="[0-9${this.decimal}]*" title="${this.title}" type="text" style="${!ComponentBaseInfo.prefix ? 'text-indent:10px' : 'text-indent:0px'}"  placeholder="${this.placeholder}" class="TeldDiscountComponent_value" placeholder="${this.placeholder}">
			${
        !ComponentBaseInfo.suffix && this.type != 'discount'
          ? ''
          : `
			<span class="TeldDiscountComponent_suffix" >
					${ComponentBaseInfo.suffix ? ComponentBaseInfo.suffix : '%'}
			</span>
			`
      }
		${
      this.type != 'discount' && this.showSpinButtons
        ? `
		<span class="TeldComponent_steps">
				<i class='triangleTop'></i>
				<i  class='triangleBottom'></i>
			</span>
		`
        : ''
    }


		</div>
		`;

    this.element.innerHTML = html;
    this.bindEvent();
    if (this.readonly) {
      this.setReadOnly(true);
    }

    return this;
  }
  //增加
  subtract() {
    debugger
    if (!this.realValue) this.realValue = 0;
    this.realValue = Number(this.realValue) * 1000;
    isNaN(this.realValue) ? (this.realValue = '') : '';
    //加精度
    this.realValue += Number(this.steps * 1000);
    this.realValue = this.fiexedData(this.realValue / 1000);

    if (this.max && Number(this.max)  < this.realValue) {
      this.realValue = Number(this.max);
    }



    //回显示
    this.setValue(Number(this.realValue));
    //通知
    this.dataChange(Number(this.realValue));
  }
  //减少
  decrease() {
    debugger
    if (!this.realValue) this.realValue = 0
    //加精度
    this.realValue -= this.steps;
    this.realValue = this.fiexedData(this.realValue);
        if (
          (this.min || this.min==0) &&
          Number(this.min) > Number(this.realValue)
        ) {
          this.realValue = Number(this.min);
        }


    //回显示
    this.setValue(Number(this.realValue));
    //通知
    this.dataChange(Number(this.realValue));
  }
  fiexedData(val, precision) {
    //console.log("========this.fixedRule======", val, precision, this.fixedRule);
    if (this.fixedRule == 1) {
      return this.toUpFixed(val, precision);
    }
    return this.toLowFixed(val, '.', precision);
  }
  toLowFixed(value, decimal, precision) {
    !decimal ? (decimal = this.decimal) : '';
    value = value.toString();
    let self = this;
    !precision && precision != 0 ? (precision = self.precision) : '';
    if (precision || precision === 0) {
      let realPrecision = value.split(decimal);
      if (realPrecision[1] && realPrecision[1].length > precision) {
        realPrecision[1] = realPrecision[1].substr(0, precision);
        value = realPrecision.join(decimal);
      }
    }
    //console.log("=====toLowFixed====", value);
    return value;
  }
  toUpFixed(val, precision) {
    val = val.toString();
    if (val.indexOf('.') != -1) {
      val = val.split('.');
      let length = val[1].length;
      val = val.join('.');
      if (length > precision) {
        val = Number(val) + 1 / Math.pow(10, 3);
      }
    }
    let value = Number(val);
    if (isNaN(value)) return val;

    //console.log("=====toUpFixed====", value.toFixed(precision || this.precision));
    return value.toFixed(precision || this.precision);
  }
  bindEvent() {
    let TeldDiscountComponent_value = this.element.querySelector(
      '.TeldDiscountComponent_value',
    );
    TeldDiscountComponent_value.onfocus = () => {
      if (this.readonly) return;
      TeldDiscountComponent_value.parentNode.classList.add(
        'Teld_Multilingual_Focus',
      );
      this.ChangeLang && this.ChangeLang instanceof Function
        ? this.ChangeLang(this.getDataType(item))
        : '';
      this.focus()
    };
    TeldDiscountComponent_value.onblur = () => {
      if (TeldDiscountComponent_value.value == '-') {
        TeldDiscountComponent_value.value = '';
      }
      if (this.type == 'discount') {
        if (this.realValue < 0 || this.realValue > 10) {
          this.value = '';
          if (this.validate) {
            this.validate('');
          }
        }
      } else if ((this.max || this.min) && this.max != this.min) {
        // if (this.realValue < this.min) {
        //   if (this.validate) {
        //     this.value = '';
        //     this.validate('');
        //   }
        // } else if (this.realValue > this.max) {
        //   if (this.validate) {
        //     this.value = '';
        //     this.validate('');
        //   }
        // } else {
        //   this.validate('');
        // }
      }
      TeldDiscountComponent_value.parentNode.classList.remove(
        'Teld_Multilingual_Focus',
      );
      this.realValue =
        this.type == 'discount'
          ? this.stringToNumber(
              this.formatToStandard(this.value, this.lang),
              'zh-CN',
            )
          : this.stringToNumber(this.value == '-' ? '' : this.value, 'zh-CN');

      this.dataChange(this.value === '' ? '' : this.realValue);
      this.setValue(this.value === '' ? '' : this.realValue);
    };
    TeldDiscountComponent_value.onkeydown = evt => {
      //8 删除 13回车 30,40 上下箭头 9:Tab
      let whiteList = [8, 13, 38, 40, 9, 37, 39];
      //上下箭头支持数据的调整大小
      if (this.type != 'discount' && this.showSpinButtons) {
        switch (evt.keyCode) {
          case 38:
            this.subtract();
            evt.preventDefault();
            break;
          case 40:
            this.decrease();
            evt.preventDefault();
            break;
          default:
            break;
        }
      }
      //keycode
      let allowedCharacters = new RegExp('[0-9' + this.decimal + '-]$');
      if (this.type == 'discount') {
        allowedCharacters = new RegExp('[0-9' + this.decimal + ']$');
      }
      // 如果输入的字符不是数字或小数位分隔符，则阻止输入
      const keyCode = evt.key;
      // 删除 回车 tab 等需要切换数据
      //console.log(evt);

      if (whiteList.includes(evt.keyCode)) {
      } else if (
        evt.key == this.decimal &&
        this.value.indexOf(this.decimal) == -1
      ) {
      } else if (allowedCharacters.test(keyCode)) {
      } else if (
        (evt.keyCode >= 48 && evt.keyCode <= 57) ||
        (evt.keyCode >= 96 && evt.keyCode <= 105)
      ) {
      } else {
        this.element.querySelector('.TeldDiscountComponent_value').value = this
          .value
          ? this.value
          : '';
        evt.preventDefault();
        evt.stopPropagation();
        return false;
      }
    };
    TeldDiscountComponent_value.onkeyup = evt => {
      let elValue = this.element.querySelector(
        '.TeldDiscountComponent_value',
      ).value;
      this.value = elValue.replace(/。/gi, '.').replace(/，/gi, ',');
      if (elValue != '') {
        this.element.querySelector('.TeldDiscountComponent_value').value =
          this.value;
      }
    };

    let self = this;
    this.element
      .querySelector('.TeldDiscountComponent_value')
      .addEventListener('input', function () {
        this.value = this.value.replace(/。/gi, '.').replace(/，/gi, ',');
        var inputValue = this.value;
        if (self.type == 'discount') {
          if (!/^[0-9,.]+$/.test(inputValue)) {
            this.value = inputValue = inputValue.replace(/[^0-9,.]/g, '');
          }
        } else {
          if (!/^[0-9,.-]+$/.test(inputValue)) {
            this.value = inputValue = inputValue.replace(/[^0-9,.-]/g, '');
          }
        }
        //精度计算
        if (self.precision || self.precision === 0) {
          let precision = inputValue.split(self.decimal);
          if (precision[1] && precision[1].length > self.precision) {
            precision[1] = precision[1].substr(0, self.precision);
            this.value = inputValue = precision.join(self.decimal);
          }
        }
        //最后一位是0继续输入bucheck，在blur统一格式化
        if (
          inputValue.indexOf(self.decimal) != -1 &&
          inputValue[inputValue.length - 1] == 0
        ) {
          return;
        }
        if (
          inputValue[inputValue.length - 1] == self.decimal &&
          inputValue.indexOf(self.decimal) != inputValue.length - 1
        ) {
          this.value = inputValue = inputValue.substr(0, inputValue.length - 1);
        }
        if (self.type == 'discount') {
          inputValue = inputValue.replace(/-/gi, '');
          this.value = inputValue;
        } else {
          if (inputValue.indexOf('-') == 0) {
            if (inputValue.split('-').length > 2) {
              inputValue = '-' + inputValue.replace(/-/gi, '');
            }
          } else {
            inputValue = inputValue.replace(/-/gi, '');
          }
          this.value = inputValue;
          if (inputValue.indexOf('-') == 0 && inputValue.length == 1) {
            return;
          }
        }
        if (!inputValue) return;
        if (
          inputValue.split(self.decimal)[1] &&
          Number(inputValue.split(self.decimal)[1]) == 0
        ) {
          return;
        }
        if (inputValue.indexOf(self.decimal) == 0 && inputValue.length == 1) {
          return (this.value = '');
        }
        //过滤多位
        if (
          inputValue[inputValue.length - 1] == self.decimal &&
          inputValue.indexOf(self.decimal) == inputValue.length - 1
        ) {
        } else {
          self.realValue =
            self.type == 'discount'
              ? self.formatToStandard(this.value, self.lang)
              : self.stringToNumber(this.value, 'zh-CN');
          //超出15
          if (self.realValue.toString().length > 15) {
            self.realValue = self.realValue.toString().substr(0, 15);
          }
          let value = ''
          if (self.type == 'discount') {
            let Lang = self.formatByLanguage(self.realValue, self.lang);
            value = Lang.value;
            value = isNaN(value) ? '' : value;
          } else {
            let _precision =
              this.value.toString().indexOf(self.decimal) != -1
                ? this.value.toString().split(self.decimal)[1].length
                : 0;
            value = new Intl.NumberFormat(self.lang, {
              maximumFractionDigits: _precision,
              minimumFractionDigits: _precision,
            }).format(self.realValue);
            if (value == 0) {
              value = this.value;
            }
          }
          if (self.type == 'discount') {
            if (self.validate) {
              self.validate(self.realValue);
            }
          } else if ((self.min || self.max) && self.max != self.min) {
            if (self.realValue < self.min) {
              if (self.validate) {
                self.validate('min');
              }
            } else if (self.realValue > self.max) {
              if (self.validate) {
                self.validate('max');
              }
            } else {
              if (self.validate) {
                self.validate('');
              }
            }
          }
          this.value = this.value !== '' ? value : '';
          self.value = this.value;
        }

        //console.log(self.realValue, self.decimal, this.value);
      });
    if (this.type == 'discount') return;
    this.target = null;
    if (this.showSpinButtons) {
      this.element.querySelector('.TeldComponent_steps').onmousedown = e => {
        if (this.target) {
          this.target.classList.remove('isClick');
        }
        if (e.target.nodeName == 'I') {
          this.target = e.target;
          e.target.classList.add('isClick');
          if (e.target.classList.contains('triangleTop')) {
            this.subtract();
          } else {
            this.decrease();
          }
        }
      };
    }

    this.element.onmouseup = () => {
      if (this.target) {
        this.target.classList.remove('isClick');
      }
    };
  }
  setPlaceholder(val) {
    //if (!val) return;
    this.placeholder = val;
    this.element
      .querySelector('.TeldDiscountComponent_value')
      .setAttribute('placeholder', val);
  }
  setValue(val) {
    if (!this.element) return;
    if (val === ''|| val == null) {
      this.element.querySelector('.TeldDiscountComponent_value').value = '';
      this.dataChange('');
      this.realValue = '';
      this.value = '';
      return;
    }
    let value;
    if (this.type == 'discount') {
      if (this.lang != 'zh-CN') {
        val = this.fiexedData(Number(val), 1);
      } else {
        if (val.toString().indexOf('.') != -1) {
          val = Number(this.fiexedData(Number(val), 1));
        }
      }
      let Lang = this.formatByLanguage(val, this.lang);
      value = Lang.value;
      value = isNaN(value) ? '' : value;
    } else {
      val = this.fiexedData(Number(val));

      value = this.numberToString(val, this.lang);
    }
    this.realValue = val;
    this.element.querySelector('.TeldDiscountComponent_value').value =
      this.value = value;
  }

  setTitle(val) {
    if (!val) return;
    this.title = val;
    this.element
      .querySelector('.TeldDiscountComponent_value')
      .setAttribute('title', val);
  }
  setReadOnly(val) {
    this.readonly = val;
    // let inputList = this.element.querySelectorAll("input");
    // inputList.forEach((item) => {
    // 	if (val) {
    // 		item.setAttribute("disabled", val);
    // 	} else {
    // 		item.removeAttribute("disabled");
    // 	}
    // });
    // if (val) {
    // 	this.element.querySelector(".translateAll").style.display = "none";
    // } else {
    // 	this.element.querySelector(".translateAll").style.display = "block";
    // }
    // 注册点击，获取焦点，失去焦点事件
    let inputList = this.element.querySelectorAll('input');
    this.element
      .querySelector('.TeldDiscountComponent_value')
      .parentNode.classList.remove('Teld_Multilingual_Focus');
    inputList.forEach(item => {
      if (val) {
        item.setAttribute('readonly', '');
        // item.style.background = 'rgba(59, 59, 59, 0)';
        // item.parentNode.style.background = 'rgba(0,0,0,.05)';
        // item.parentNode.classList.add('isReadonly');
      } else {
        item.removeAttribute('readonly');
        // item.style.background = '#fff';
        // item.parentNode.style.background = '#fff';
        // item.parentNode.classList.remove('isReadonly');
        //item.querySelector('.LanguageType').style.background='#fff'
      }
    });
  }
  setLang(val) {
    this.lang = val;
    let ComponentBaseInfo = {};
    if (this.type == 'discount') {
      ComponentBaseInfo = this.formatByLanguage('', this.lang);
    } else {
      ComponentBaseInfo = {
        prefix: currencySymbols[this.lang],
        value: this.value,
      };
    }
    let prefix = !ComponentBaseInfo.prefix
      ? ''
      : `
	<span class="TeldDiscountComponent_prefix" >
		${ComponentBaseInfo.prefix}
	</span>`;

    let suffix = !ComponentBaseInfo.suffix
      ? ''
      : `
	<span class="TeldDiscountComponent_suffix">
			${ComponentBaseInfo.suffix ? ComponentBaseInfo.suffix : '%'}
	</span>
	`;
    let Html = `
		${prefix}
		<input tabindex=${this.tabindex} pattern="[0-9${this.decimal}]*" title="${this.title}" type="text" style="${!ComponentBaseInfo.prefix ? 'text-indent:10px' : 'text-indent:0px'}"  placeholder="${this.placeholder}" class="TeldDiscountComponent_value" placeholder="${this.placeholder}">
		${suffix}
		`;
    this.element
      .querySelector('.TeldDiscountComponent')
      .setAttribute(
        'style',
        `${!ComponentBaseInfo.prefix ? 'grid-template-columns: 1fr auto;' : 'grid-template-columns: auto 1fr auto;'}`,
      );
    this.element.querySelector('.TeldDiscountComponent_value').value = isNaN(
      ComponentBaseInfo.value,
    )
      ? ''
      : ComponentBaseInfo.value;
    this.element.querySelector('.TeldDiscountComponent').innerHTML = Html;
    this.bindEvent();
  }
  numberToString(nmb, local = navigator.language, useGrouping = true) {
    if (
      window.TFF &&
      window.TFF.common.api &&
      window.TFF.common.api.I18N.numberToString
    ) {
      return window.TFF.common.api.I18N.numberToString(
        nmb,
        local,
        this.precision,
        useGrouping,
      );
    }
    let decimal = '.';
    let _precision =
      nmb.toString().indexOf(decimal) != -1
        ? nmb.toString().split(decimal)[1].length
        : 0;
    let precision = this.precision;
    if (!this.precision && this.precision != 0) {
      precision = _precision;
    }
    return new Intl.NumberFormat(local, {
      maximumFractionDigits: precision,
      minimumFractionDigits: precision,
      useGrouping: useGrouping,
    }).format(nmb);
  }

  stringToNumber(nmbStr, local = navigator.language) {
    if (!nmbStr && nmbStr != '0') return '';
    // let group = new Intl.NumberFormat(local).format(1111).replace(/1/g, "");
    // let decimal = new Intl.NumberFormat(local).format(1.1).replace(/1/g, "");
    let reversedVal = nmbStr.replace
      ? nmbStr
          .replace(new RegExp('\\' + this.group, 'g'), '')
          .replace(new RegExp('\\' + this.decimal, 'g'), '.')
      : nmbStr;
    return Number(reversedVal);
  }
  // 按照语言格式化
  formatByLanguage(discount, local = navigator.language) {
    // if (window.TFF && window.TFF.common.api.I18N.getDetailDiscountRate) {
    // 	return window.TFF.common.api.I18N.getDetailDiscountRate(discount, local);
    // }
    let formats = {
      'en-US': {
        prefix: '',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      }, // 美国
      'es-ES': {
        prefix: '',
        suffix: '% de descuento',
        value: 1 * 10 - discount * 1,
      },
      'es-MX': {
        prefix: '',
        suffix: '% de descuento',
        value: 1 * 100 - discount * 10,
      },
      'zh-TW': {
        prefix: '',
        suffix: '折',
        value: discount,
      },
      'id-ID': {
        prefix: 'diskon ',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      },
      'ms-MY': {
        prefix: 'diskaun ',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      },
      'th-TH': {
        prefix: 'ลด ',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      },
      'vi-VN': {
        prefix: 'giảm ',
        suffix: '%',
        value: 1 * 100 - discount * 10,
      },
      'tl-PH': {
        prefix: '',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      },
      'pt-BR': {
        prefix: '',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      },
      'zh-HK': {
        prefix: '',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      },
      'en-GB': {
        prefix: '',
        suffix: '% off',
        value: 1 * 100 - discount * 10,
      },
      'zh-CN': {
        prefix: '',
        suffix: '折',
        value: discount,
      },
      'ja-JP': {
        prefix: '',
        suffix: '%引き',
        value: 1 * 100 - discount * 10,
      },
      'de-DE': {
        prefix: '',
        suffix: 'Rabatt',
        value: 1 * 100 - discount * 10,
      },
      'fr-FR': {
        prefix: '',
        suffix: '% de réduction',
        value: 1 * 100 - discount * 10,
      },
      'it-IT': {
        prefix: 'sconto del ',
        suffix: '%',
        value: 1 * 100 - discount * 10,
      },
      'ru-RU': {
        prefix: 'скидка ',
        suffix: '%',
        value: 1 * 100 - discount * 10,
      },
    };
    let value = formats[local] || '';
    return value;
  }
  //将输入值格式化为标准格式
  formatToStandard(discount, local = navigator.language) {
    discount = this.stringToNumber(discount, 'zh-CN');
    // 为了处理精度问题 统一*100 进行处理
    // if (window.TFF && TFF.common.api.I18N.getDiscountRateToNumber) {
    // 	return TFF.common.api.I18N.getDiscountRateToNumber(discount, local);
    // }
    let formats = {
      'en-US': (100 - discount) / 10,
      'es-ES': (100 - discount) / 10,
      'es-MX': (100 - discount) / 10,
      'zh-TW': discount,
      'id-ID': (100 - discount) / 10,
      'ms-MY': (100 - discount) / 10,
      'th-TH': (100 - discount) / 10,
      'vi-VN': (100 - discount) / 10,
      'tl-PH': (100 - discount) / 10,
      'pt-BR': (100 - discount) / 10,
      'zh-HK': (100 - discount) / 10,
      'en-GB': (100 - discount) / 10,
      'zh-CN': discount,
      'ja-JP': (100 - discount) / 10,
      'de-DE': (100 - discount) / 10,
      'fr-FR': (100 - discount) / 10,
      'it-IT': (100 - discount) / 10,
      'ru-RU': (100 - discount) / 10,
    };
    return isNaN(formats[local]) ? '' : formats[local];
  }
}

;

const currencySymbols = {
	"en-US": "$",
	"en-CA": "$",
	"en-GB": "£",
	"en-IE": "€",
	ja: "¥",
	"zh-CN": "¥",
	"zh-HK": "HK$",
	"zh-TW": "NT$",
	"ar-AE": "د.إ",
	"ar-BH": "ر.ب",
	"ar-JO": "د.أ",
	"ar-KW": "ر.ك",
	"ar-LB": "ل.ل",
	"ar-MA": "د.م.",
	"ar-QA": "ر.ق",
	"ar-SA": "ر.س",
	"ar-SY": "ل.س",
	"ar-TN": "د.ت",
	"ar-YE": "ر.ي",
	be: " BelarusianBelarusian_Belarusian (be)$BYN",
	bg: " BulgarianBulgarian_Bulgaria (bg)$BGN",
	ca: " CatalanCatalan_Catalan (ca)$EUR",
	cs: " CzechCzech_Czech Republic (cs)$CZK",
	da: " DanishDanish_Denmark (da)$DKK",
	de: " GermanGerman_Germany (de)$EUR",
	el: " GreekGreek_Greece (el)$EUR",
	"en-AU": "$",
	"en-CA": "$",
	"en-GB": "£",
	"en-IE": "€",
	"en-IN": "$",
	"en-NZ": "$",
	"en-PH": "$",
	"en-SG": "$",
	"en-US": "$",
	"es-AR": "$",
	"es-BO": "$",
	"es-CL": "$",
	"es-CO": "$",
	"es-CR": "$",
	"es-CU": "$",
	"es-DO": "$",
	"es-EC": "$",
	"es-ES": "€",
	"es-GT": "$",
	"es-HN": "$",
	"es-IC": "€",
	"es-MX": "$",
	"es-NI": "$",
	"es-PA": "$",
	"es-PE": "$",
	"es-PR": "$",
	"es-PY": "$",
	"es-SV": "$",
	"es-US": "$",
	"es-UY": "$",
	"es-VE": "Bs",
	fi: " Finnish_Finland (fi)€",
	"fi-SE": "€",
	fr: "French_France (fr)€",
	"fr-BE": "€",
	"fr-CA": "€",
	"fr-CH": "€",
	"fr-LU": "€",
	"fr-MC": "€",
	hr: "Croatian_Croatia (hr)Kn",
	"hr-HR": "Kn",
	hu: " Hungarian_Hungary (hu)Ft",
	"hu-HU": "Ft",
	id: " Indonesian_Indonesia (id)Rp",
	"id-ID": "Rp",
	is: " Icelandic_Iceland (is)Kr",
	"is-IS": "Kr",
	it: " Italian_Italy (it)€",
	"it-CH": "€",
	ja: " Japanese_Japan (ja)¥",
	"ja-JP": "¥",
	ka: " Georgian_Georgia (ka)Lari",
	"ka-GE": "Lari",
	kk: " Kazakh_Kazakhstan (kk)лв",
	"kk-KZ": "лв",
	kl: " Greenlandic_Greenland (kl)DKK",
	"kl-GL": "DKK",
	km: " Khmer_Cambodia (km)៛",
	"km-KH": "៛",
	kn: " Kannada_India (kn)₹",
	"kn-IN": "₹",
	ko: " Korean_Korea (ko)₩",
	"ko-KP": "₩",
	"ko-KR": "₩",
	ky: " Kyrgyz_Kyrgyzstan (ky)сўм",
	"ky-KG": "сўм",
	lb: " Luxembourgish_Luxembourg (lb)€",
	"lb-LU": "€",
	lo: " Lao_Laos (lo)₭",
	"lo-LA": "₭",
	lt: " Lithuanian_Lithuania (lt)Lt",
	"lt-LT": "Lt",
	lv: " Latvian_Latvia (lv)Ls",
	"lv-LV": "Ls",
	mi: " Maori_New_Zealand (mi)NZ$",
	"mi-NZ": "NZ$",
	mk: " Macedonian_Macedonia (mk)ден",
	"mk-MK": "ден",
	mn: " Mongolian_Mongolia (mn)₮",
	"mn-MN": "₮",
	mr: " Marathi_India (mr)₹",
	"mr-IN": "₹",
	ms: " Malaysian_Malaysia (ms)RM",
	"ms-BN": "RM",
	"ms-MY": "RM",
	mt: " Maltese_Malta (mt)€",
	"mt-MT": "€",
	my: " Burmese_Myanmar (my)Ks",
	"my-MM": "Ks",
	nb: " Norwegian Bokmål_Norway (nb)kr",
	"nb-NO": "kr",
	ne: " Nepali_Nepal (ne)Rs",
	"ne-NP": "Rs",
	nl: " Dutch_Netherlands (nl)€",
	"nl-BE": "€",
	"nl-NL": "€",
	nn: " Norwegian Nynorsk_Norway (nn)kr",
	"nn-NO": "kr",
	pa: " Punjabi_India (pa)₹",
	"pa-IN": "₹",
	pl: " Polish_Poland (pl)zł",
	"pl-PL": "zł",
	ps: " Pashto_Afghanistan (ps)؋",
	"ps-AF": "؋",
	pt: " Portuguese_Portugal (pt)€",
	"pt-BR": "R$",
	"pt-PT": "€",
	ro: " Romanian_Romania (ro)L",
	"ro-RO": "L",
	ru: " Russian_Russia (ru)р.",
	"ru-RU": "₽",
	sd: " Sindhi_India (sd)₨",
	"sd-IN": "₨",
	se: " Northern Sami_Finland (se)€",
	"se-FI": "€",
	si: " Sinhalese_Sri Lanka (si)LK₨",
	"si-LK": "lk₨",
	sk: " Slovak_Slovakia (sk)€",
	"sk-SK": "€",
	sl: " Slovenian_Slovenia (sl)€",
	"sl-SI": "€",
	sq: " Albanian_Albania (sq)Lek",
	"sq-AL": "Lek",
	sr: " Serbian_Serbia (sr)din.",
	"sr-Cyrl": "din.",
	"sr-Latn": "din.",
	"sr-RS": "din.",
	sv: " Swedish_Sweden (sv)kr",
	"sv-SE": "kr",
	sw: " Swahili_Tanzania (sw)Sh",
	"sw-TZ": "Sh",
	ta: " Tamil_India (ta)₹",
	"ta-IN": "₹",
	te: " Telugu_India (te)₹",
	"te-IN": "₹",
	tg: " Tajik_Tajikistan (tg)ЅМ",
	"tg-TJ": "ЅМ",
	th: " Thai_Thailand (th)฿",
	"th-TH": "฿",
	tl: " Tagalog_Philippines (tl)₱",
	"tl-PH": "₱",
	tr: " Turkish_Turkey (tr)₺",
	"tr-TR": "₺",
	tt: " Tatar_Russia (tt)₽",
	"tt-RU": "₽",
	uk: " Ukrainian_Ukraine (uk)₴",
	"uk-UA": "₴",
	ur: " Urdu_Pakistan (ur)₨",
	"ur-PK": "₨",
	uz: " Uzbek_Uzbekistan (uz)soʻm",
	"uz-Cyrl": "сўм",
	"uz-Latn": "soʻm",
	"uz-UZ": "soʻm",
	vi: " Vietnamese_Vietnam (vi)₫",
	"vi-VN": "₫",
	zh: " Chinese_China (zh)¥",
	"zh-CN": "¥",
	"zh-HK": "HK$",
	"zh-MO": "MOP$",
	"zh-SG": "S$",
	"zh-TW": "NT$",
	zu: " Zulu_South Africa (zu)R",
	"zu-ZA": "R",
};
